/// @tags: DP TCP by length
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define rint register int

using std::cin;
using std::cout;

namespace BlueQuantum {

typedef long long ll;
const int MAXN = 3e2 + 5;
#define getc() \
  p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++;
char buf[1 << 21], *p1, *p2, ch;
int retint;
ll retll;
inline int readint() {
  retint = 0;
  char c = getc();
  while (c < '0' || c > '9') c = getc();
  while (c >= '0' && c <= '9') retint = retint * 10 + c - '0', c = getc();
  return retint;
}
inline ll readll() {
  retll = 0;
  char c = getc();
  while (c < '0' || c > '9') c = getc();
  while (c >= '0' && c <= '9') retll = retll * 10 + c - '0', c = getc();
  return retll;
}

int N;
ll K, ans;
struct node {
  int v, next;
} E[MAXN];
int head[MAXN], Elen;
void add(int u, int v) { ++Elen, E[Elen].v = v, E[Elen].next = head[u], head[u] = Elen; }
int maxdep[MAXN], wson[MAXN];
void dfs1(int u) {
  for (int i = head[u]; i; i = E[i].next) {
    dfs1(E[i].v);
    if (maxdep[E[i].v] > maxdep[wson[u]]) wson[u] = E[i].v;
  }
  maxdep[u] = maxdep[wson[u]] + 1;
}
int buc[MAXN * 2], *p, *q, *f[MAXN], tag[MAXN], *g[MAXN];
ll buk[MAXN];
void dfs2(int u) {
  if (wson[u]) {
    f[wson[u]] = f[u] + 1, g[wson[u]] = g[u] + 1, dfs2(wson[u]);
    tag[u] = tag[wson[u]];
  }
  ++f[u][0], g[u][0] = tag[u], ++tag[u];
  for (int i = head[u]; i; i = E[i].next)
    if (E[i].v != wson[u]) {
      f[E[i].v] = p, p += maxdep[E[i].v], g[E[i].v] = q, q += maxdep[E[i].v], dfs2(E[i].v);
      for (int j = 0; j < maxdep[E[i].v]; ++j) {
        buk[f[E[i].v][j]] += tag[E[i].v] - g[E[i].v][j];
        buk[f[u][j + 1]] += tag[u] - g[u][j + 1] - 1, g[u][j + 1] = tag[u] - 1;
        f[u][j + 1] += f[E[i].v][j];
      }
    }
}

int main() {
  N = readint(), K = readll();
  int u, v;
  for (int i = 2; i <= N; ++i) add(readint(), i);
  dfs1(1);
  p = buc, q = buc + N;
  f[1] = p, p += maxdep[1], g[1] = q, q += maxdep[1], dfs2(1);
  for (int i = 0; i < maxdep[1]; ++i) buk[f[1][i]] += tag[1] - g[1][i];
  for (int i = N; i >= 1; --i) {
    if (buk[i] <= K)
      ans += 1ll * buk[i] * i, K -= buk[i];
    else {
      ans += 1ll * K * i;
      break;
    }
  }
  printf("%lld", ans);
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("light.in", "r", stdin);
  freopen("light.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
